<?php

class FormProcessor_AddHelpPage extends FormProcessor {
    
    public $page = null;
    
    public function __construct($db) {
        parent::__construct();
        $this->page = new DatabaseObject_HelpPages($db);
    }
    
    public function process(Zend_Controller_Request_Abstract $request) {
        
        $this->name = trim($request->getPost('name'));
        
        if(strlen($this->name) == 0) {
            $this->addError ('name', 'Вы должны указать название страницы');
        } else {
            $this->page->name = $this->name;
        }
        
        $this->h1 = trim($request->getPost('h1'));
        
        if(strlen($this->h1) == 0) {
            $this->addError ('h1', 'Вы должны указать h1 страницы');
        } else {
            $this->page->h1 = $this->h1;
        }
        
        $this->content = trim($request->getPost('content'));
        
        if(strlen($this->content) == 0) {
            $this->addError ('content', 'Вы должны указать содержимое страницы');
        } else {
            $this->page->content = $this->content;
        }
        
        $this->alias = trim($request->getPost('alias'));
        
        if(strlen($this->alias) == 0) {
            $this->addError ('alias', 'Вы должны указать содержимое страницы');
        } else {
            $this->page->alias = $this->alias;
        }
        
        $this->title = $request->getPost('title');
        $this->page->title = $this->title;
        
        $this->keywords = $request->getPost('keywords');
        $this->page->keywords = $this->keywords;
        
        $this->description = $request->getPost('description');
        $this->page->description = $this->description;
        
        $this->cat_id = $request->getPost('cat_id');
        $this->page->cat_id = $this->cat_id;
        
        $this->isPopular = $request->getPost('ispop') == 'on' ? 1 : 0;
        $this->page->isPopular = $this->isPopular;
        
        $this->isRecommend = $request->getPost('isrec') == 'on' ? 1 : 0;
        $this->page->isRecommend = $this->isRecommend;
        
        if(!$this->hasError()) {
            $this->page->save();
        }
        
        return !$this->hasError();
    }    
}
